<?php
error_reporting(0);
$id=$_GET['id']; 

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("morganse_crm") or die(mysql_error());
$array=array();


// App Info array['app']['xxx']
$sql="SELECT * FROM crm_application WHERE comesfrom='MaxFinance' AND IdenticalID =".$id;
$result = mysql_query($sql) or die(mysql_error());
$row = MYSQL_FETCH_ASSOC($result);
FOREACH ($row as $key=>$value){
	$array['app'][$key]=$value;
}


// Client1&2 info array['client1']['xxx'] , array['client2']['xxx']
$sql="SELECT * FROM crm_contact WHERE comesfrom='MaxFinance' AND app_id =".$id;
$result = mysql_query($sql) or die(mysql_error());
$i='client1';
WHILE($row = MYSQL_FETCH_ASSOC($result))// put client fields into array
{
	FOREACH($row AS $key=>$value)
		$array[$i][$key]=$value;
	$i='client2';
}


// Employment1&2 Info array['emp1']['xxx'],array['emp2']['xxx']
$sql="SELECT * FROM crm_employment WHERE Comesfrom='MaxFinance' AND IdenticalID =".$id;
$result = mysql_query($sql) or die(mysql_error());
$i='emp1';
WHILE($row = MYSQL_FETCH_ASSOC($result))// put employment fields into array
{
	FOREACH($row AS $key=>$value)
		$array[$i][$key]=$value;
	$i='emp2';
}



// Credit History 1&2 info array['credit1']['xxx'] , array['credit2']['xxx']
$sql="SELECT * FROM crm_applicationcredit WHERE comesfrom='MaxFinance' AND IdenticalID =".$id;
$result = mysql_query($sql) or die(mysql_error());
$i='credit1';
WHILE($row = MYSQL_FETCH_ASSOC($result))// put credit fields into array
{
	FOREACH($row AS $key=>$value)
		$array[$i][$key]=$value;
	$i='credit2';
}



$homeaddress1= $array['client1']['StreetNo']." ".$array['client1']['Street']." ".$array['client1']['Suburb']." ".$array['client1']['State']." ".$array['client1']['PostCode'];
$homeaddress2= $array['client2']['StreetNo']." ".$array['client2']['Street']." ".$array['client2']['Suburb']." ".$array['client2']['State']." ".$array['client2']['PostCode'];


// Income array
$sql="SELECT * FROM crm_income WHERE Comesfrom='MaxFinance' AND IdenticalID =".$id;
$result = mysql_query($sql) or die(mysql_error());
$i=1;
WHILE($row = MYSQL_FETCH_ASSOC($result))// put income fields into array
{
	FOREACH($row AS $key=>$cell)
		$arrayincome[$i][$key]=$cell;
	$i++;
}
$wincome1 = $arrayincome[1]['income_aftertax']; //echo $wincome1;
$wincome2 = $arrayincome[2]['income_aftertax'];

$wincome1p = $arrayincome[1]['income_aftertax_period'];
$wincome2p = $arrayincome[2]['income_aftertax_period'];

$cincome1 = $arrayincome[1]['income_centrelink'];
$cincome2 = $arrayincome[2]['income_centrelink'];

$oincome1 = $arrayincome[1]['income_other'];
$oincome2 = $arrayincome[2]['income_other'];

$oincome1p = $arrayincome[1]['income_other_period'];
$oincome2p = $arrayincome[2]['income_other_period'];

$oincome1spec = $arrayincome[1]['OtherIncomeSpecify'];
$oincome2spec = $arrayincome[2]['OtherIncomeSpecify'];
?>



<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>form view</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link href="http://maxfunding.com.au/bootstrap/css/bootstrap.css" rel="stylesheet">
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script> 
<script src="form-view-js.js"></script>
<link rel="stylesheet" type="text/css" href="form-vew-style.css">
<style>
.container{
	box-shadow: 10px 0px 10px -10px rgba(0,0,0,0.45), -10px 0px 10px -10px rgba(0,0,0,0.45);
}
#header-table{
	border:none;
}
#header-table tr td{
	border:none;
}
.grey-bg{
	background-color:#ccc;
}
h3{
	padding:20px 0 5px 0
}
</style>
</head>

<body>
<!--<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to"><br><br><br>-->
<div class="container" style="background-color:white;">
<h2 class="text-center">Final Verification Sheet (Personal Loans)</h2>
<div class="pull-right"><h4>Verify by: ______________________</h4></div>
<div class="clearfix"></div>

<table id="header-table">
  <tr>
    <td width="55%"><h3><?php echo '<strong>'.$array['client1']['FirstName'].'</strong> '.$array['client1']['SurName']; ?></h3></td>
    <td width="15%"><strong>AppID</strong>: <?php echo $array['app']['app_id']; ?></td>
    <td width="15%"><strong>Date</strong>: <?php echo $array['app']['CreatedDate']; ?></td>
    <td width="15%"><strong>Time</strong>: <?php echo $array['app']['CreatedTime']; ?></td>
  </tr>
</table>

<h3>Assumtion:</h3>
<p>1. Minimum documents has been received</p>
<table style="background-color:#ffff00">
  <tr>
    <td width="33%"><strong>Desired Amount</strong></td>
    <td><?php echo $array['app']['DesiredAmount']; ?></td>
  </tr>
</table>

<h3>Personal Details</h3>
<table id="personal-table">
    <tr>
      <td width="33%">Title</td>
      <td width="33%"><?php echo $array['client1']['Title']?></td>
      <td id="title2"><?php echo $array['client2']['Title']?></td>
    </tr>
    <tr class="yellow-bg">
      <td>Full Name</td>
      <td><?php echo $array['client1']['FirstName']." ".$array['client1']['MiddleName']." ".$array['client1']['SurName']?></td>
      <td><?php echo $array['client2']['FirstName']." ".$array['client2']['MiddleName']." ".$array['client2']['SurName']?></td>
    </tr>
    <tr class="yellow-bg">
      <td>Citizenship</td>
      <td><?php echo $array['client1']['Citizenship']?></td>
      <td><?php echo $array['client2']['Citizenship']?></td>
    </tr>
    <tr class="yellow-bg">
      <td>Mobile</td>
      <td><?php echo $array['client1']['Mobile']?></td>
      <td><?php echo $array['client2']['Mobile']?></td>
    </tr>
    <tr class="yellow-bg">
      <td>Home Phone</td>
      <td><?php echo $array['client1']['HomePhone']?></td>
      <td><?php echo $array['client2']['HomePhone']?></td>
    </tr>
    <tr class="yellow-bg">
      <td>Email</td>
      <td><?php echo $array['client1']['Email']?></td>
      <td><?php echo $array['client2']['Email']?></td>
    </tr>
    <tr class="yellow-bg">
      <td>Home Address</td>
      <td><?php echo "<a class='address'>".$homeaddress1."</a>" ?></td>
      <td><?php echo "<a class='address'>".$homeaddress2."</a>" ?></td>
    </tr>
   	<tr class="yellow-bg">
    	<td>Date of Birth</td>
    	<td><span id="dob1"><?php echo $array['client1']['DateBirth']?></span> <span id="age1"></span>  </td>
    	<td><span id="dob2"><?php echo $array['client2']['DateBirth']?></span> <span id="age2"></span>  </td>
  	</tr>
    <tr>
      <td>Driver License</td>
      <td><?php echo $array['client1']['DriverLicense']?></td>
      <td><?php echo $array['client2']['DriverLicense']?></td>
    </tr>
    <tr>
      <td>Residential Status</td>
      <td><?php echo $array['client1']['app_ResidentialStatus']?></td>
      <td><?php echo $array['client2']['app_ResidentialStatus']?></td>
    </tr>
    <tr>
      <td>Number of Dependant</td>
      <td id="nod"><?php echo $array['client1']['Dependant']?></td>
      <td><?php echo $array['client2']['Dependant']?></td>
    </tr>
  </table>

<h3>Liabilities</h3>
<?php
// Liability Info
$sql="SELECT * FROM crm_liabilities WHERE Comesfrom='MaxFinance' AND IdenticalID =".$id;
$result = mysql_query($sql) or die(mysql_error());
echo "<table class='liability-table'><tr>";
$fields_num = MYSQL_NUM_FIELDS($result);
FOR($i=0; $i<$fields_num; $i++)
{
	$field = MYSQL_FETCH_FIELD($result);
	ECHO "<td>{$field->name}</td>";
}echo "</tr>";
WHILE($row = mysql_fetch_assoc($result))
{
	ECHO "<tr>";
	FOREACH($row AS $key=>$cell)
		echo "<td width='25%'>".$cell."</td>";
	ECHO "</tr>";
}
echo "</table>";
// Liability Info END
?>


<h3>Bank Statement Factors (Not considered by iDecision)</h3>
<table style="background-color:#FFFF00" border="1" cellpadding="0" cellspacing="0" width="100%">
      	  <tbody><tr>
      	    <td>
            <p class="doc"><img src="http://www.mycashfinance.com.au/email/Box.png" style="float:left">&nbsp;Gambling activitiew (The Star, TAB,etc)</p>
   	        <p class="doc"><img src="http://www.mycashfinance.com.au/email/Box.png" style="float:left">&nbsp;3 or more dishonours</p>
   	        <p class="doc">Refer to supervisor for review</p></td>
      	    <td>
            <p class="doc"><img src="http://www.mycashfinance.com.au/email/Box.png" style="float:left">&nbsp;Gambling activitiew (The Star, TAB,etc)</p>
            <p class="doc"><img src="http://www.mycashfinance.com.au/email/Box.png" style="float:left">&nbsp;3 or more dishonours</p>
   	        <p class="doc">Refer to supervisor for review</p></td>

    </tr>
</tbody></table>


<h3>Asset - <?php echo $array['app']['mc_asset_status'];?>  <span style="float:right" >PASS? <img src="http://www.mycashfinance.com.au/email/Box.png"></img></span></h3>
<?php
// vehicle table
$sql="SELECT * FROM crm_vehicle WHERE Comefrom='MaxFinance' AND IdenticalID =".$id;
$result = mysql_query($sql) or die(mysql_error());
echo "<table class='vehicle-table'>";
ECHO "<tr>";
$fields_num = MYSQL_NUM_FIELDS($result);
FOR($i=0; $i<$fields_num; $i++)
{
	$field = MYSQL_FETCH_FIELD($result);
	ECHO "<td width='25%'>{$field->name}</td>";
}
ECHO "</tr>\n";

WHILE($row = MYSQL_FETCH_ASSOC($result))
{
	
	ECHO "<tr>";

	// $row is array... foreach( .. ) puts every element
	// of $row to $cell variable
	FOREACH($row AS $key=>$cell){
		if($key=="VehicleValue")
			ECHO "<td class='currency'>$cell</td>";
		else
			ECHO "<td>$cell</td>";
	}
	ECHO "</tr>\n";
}
echo "</table>";
// vehicle table END








// 2 property tables
$sql="SELECT * FROM crm_property WHERE Comefrom='MaxFinance' AND IdenticalID =".$id;
$result = mysql_query($sql) or die(mysql_error());

$i=1;
$col='property'.$i;
WHILE($row = MYSQL_FETCH_ASSOC($result))
{
	FOREACH($row AS $key=>$value)
		$array[$col][$key]=$value;
	$i++;
	$col='property'.$i;
}

// property short table
echo '
	<table class="property-short-table">
		<tr style="background:#d9edf7">
			<td>Property</td>
			<td>Current Value</td>
			<td>Amount Owing</td>
			<td>LVR%</td>
			<td>Bank/Financier</td>
			<td>Owners Name</td>
		</tr>
';
for($j=1;$j<=6;$j++){
	if($array["property".$j]["PropertyValue"]!=''){
		echo '
			<tr>
				<td>Real Estate '.$j.'</td>
				<td class="currency" id=propertyValue'.$j.'>'.$array["property".$j]["PropertyValue"].'</td>
				<td class="currency" id=propertyOwing'.$j.'>'.$array["property".$j]["MortgageOwing"].'</td>
				<td id=LVR'.$j.'></td>
				<td>'.$array["property".$j]["MortgageLender"].'</td>
				<td>'.$array["property".$j]["Owner"].'</td>
			</tr>
		';
	}
}
echo '</table>';
// property short table END





// property details table
for($j=1;$j<=5;$j+=2){
	$k=$j+1;
	echo '
		<table class="property-table">
			<tr style="background:#d9edf7">
				<td width="33%"><strong></strong></td>
				<td width="33%"><strong>Property '.$j.'</strong></td>
				<td><strong>Property '.$k.'</strong></td>
			</tr>
							
			<tr>
				<td>Address</td>
				<td><a class="address">'.$array["property".$j]["Address"].'</a></td>
				<td><a class="address">'.$array["property".$k]["Address"].'</a></td>
			</tr>
			
			<tr>
				<td>Arrears</td>
				<td>'.$array["property".$j]["Arrears"].'</td>
				<td>'.$array["property".$k]["Arrears"].'</td>
			</tr>
		</table>
	';
}
// property details table END
?>

<h3>Credit- <?php echo $array['app']['mc_credit_status'];?>  <span style="float:right" >PASS? <img src="http://www.mycashfinance.com.au/email/Box.png"></img></span></img></h3>
<p>
  <table id="credit-table">
    <tr>
      <td width="33%">Have  you ever applied for bankruptcy or hardship?</td>
      <td width="33%"><?php echo $array['credit1']['credit_hardship']?></td>
      <td><?php echo $array['credit2']['credit_hardship']?></td>
    </tr>
    <tr>
      <td>Your credit history?</td>
      <td><?php echo $array['credit1']['credit_history']?></td>
      <td><?php echo $array['credit2']['credit_history']?></td>
    </tr>
    <tr>
      <td>Total Outstanding Value </td>
      <td><?php echo $array['credit1']['credit_outstanding']?></td>
      <td><?php echo $array['credit2']['credit_outstanding']?></td>
    </tr>
    <tr>
      <td>Discharge Date </td>
      <td><?php echo $array['credit1']['credit_dischargedate']?></td>
      <td><?php echo $array['credit2']['credit_dischargedate']?></td>
    </tr>
    <tr>
      <td>Discharge </td>
      <td><?php echo $array['credit1']['credit_discharge']?></td>
      <td><?php echo $array['credit2']['credit_discharge']?></td>
    </tr>
  </table>
</p>


<!-- employment -->
<h3>Employment</h3>
<table>
  <tr>
    <td width="33%">Employment Status</td>
    <td width="33%"><?php echo $array['emp1']['employment_status']; ?></td>
    <td><?php echo $array['emp2']['employment_status']; ?></td>
  </tr>
  <tr>
    <td>Type of Employment</td>
    <td><?php echo $array['emp1']['employment_type']; ?></td>
    <td><?php echo $array['emp2']['employment_type']; ?></td>
  </tr>
  <tr>
    <td>Employer Name</td>
    <td><?php echo $array['emp1']['employer_name']; ?></td>
    <td><?php echo $array['emp2']['employer_name']; ?></td>
  </tr>
  <tr>
    <td>Title in Occupation</td>
    <td><?php echo $array['emp1']['employment_occupation']; ?></td>
    <td><?php echo $array['emp2']['employment_occupation']; ?></td>
  </tr>
  <tr>
    <td>Work Phone for Contact Person</td>
    <td><?php echo $array['emp1']['employer_phone']; ?></td>
    <td><?php echo $array['emp2']['employer_phone']; ?></td>
  </tr>
</table>

<!-- income calculation -->
<h3>Disposable Income Calculator ( <span class="doc"><img src="http://www.mycashfinance.com.au/email/Box.png" alt=""></span> Complete this table or  <span class="doc"><img src="http://www.mycashfinance.com.au/email/Box.png" alt=""></span> use I & E worksheet)</h3>
<table width="200" border="1">
  <tr>
    <td>&nbsp;</td>
    <td><strong>Declared</strong></td>
    <td><strong>Actual on bank statement</strong></td>
  </tr>
  <tr>
    <td><strong>Work Income</strong></td>
    <td><?php echo $wincome1.' '.$wincome1p.'<br>'.$wincome2.' '.$wincome2p; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Centrelink</strong></td>
    <td><?php echo $cincome1.'<br>'.$cincome2; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Other Income</strong></td>
    <td><?php echo $oincome1.' '.$oincome1p;
				echo $oincome1spec.'<br>';
				echo $oincome2.' '.$oincome2p;
				echo $oincome2spec;
	 ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr class="grey-bg">
    <td><strong>Total</strong></td>
    <td><?php echo $array['app']['totalincome']; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Expenses</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><p><strong>Standard Exp.</strong></p>
      <p><strong>Declared Exp.</strong></p></td>
    <td><span id="standard"></span><br>
    <?php echo $array['app']['livingfee']; ?>
    
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Credit Commit</strong></td>
    <td><?php echo $array['app']['totalexpensecorrect']; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Boarding/Renting</strong></td>
    <td><?php echo $array['app']['boardingfee']; ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr class="grey-bg">
    <td><strong>Disposable Income</strong></td>
    <td><strong><?php echo $array['app']['disposableincome']; ?></strong></td>
    <td>Repayment:</td>
  </tr>
</table>







<h3>Eligible Amount - Reference: iDecision: <?php echo $array['app']['ELA']?></h3>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
  <tbody><tr>
    <td colspan="6" style="border-bottom:0;"><p class="doc">Amount based on Asset $_________________ &nbsp;&nbsp;&nbsp;&nbsp;(Per factor decrease or increase $100-$500)</p></td>
  </tr>
  <tr>
    <td style="border-bottom:0; border-top:0;" width="2%">&nbsp;</td>
    <td width="23%"><p class="doc"><strong>Increase Amount factors</strong></p></td>
    <td width="20%">&nbsp;</td>
    <td width="23%"><p class="doc"><strong>Decrease Amount factors</strong></p></td>
    <td width="20%">&nbsp;</td>
    <td style="border-bottom:0; border-top:0;" width="2%">&nbsp;</td>
  </tr>
  <tr>
    <td style="border-bottom:0; border-top:0;">&nbsp;</td>
    <td><p class="doc">High Income($800+ pw)</p></td>
    <td><p class="doc">+</p></td>
    <td><p class="doc">Bad credit history</p></td>
    <td><p class="doc">&nbsp;-</p></td>
    <td style="border-bottom:0; border-top:0;">&nbsp;</td>
  </tr>
  <tr>
    <td style="border-bottom:0; border-top:0;">&nbsp;</td>
    <td><p class="doc">High Dispos. Income ($1k p.m.)</p></td>
    <td><p class="doc">+</p></td>
    <td>Poor Financial Management</td>
    <td>-</td>
    <td style="border-bottom:0; border-top:0;">&nbsp;</td>
  </tr>
  <tr>
    <td style="border-bottom:0; border-top:0;">&nbsp;</td>
    <td><p class="doc">Good Credit</p></td>
    <td><p class="doc">+</p></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td style="border-bottom:0; border-top:0;">&nbsp;</td>
  </tr>
  
  
  
  
  <tr>
    <td colspan="6" style="border-top:0;" height="24px;"><p class="doc" align="center">Final Amount $_________________ &nbsp;&nbsp;&nbsp;or&nbsp;&nbsp;&nbsp; Financed vehicle rule $1,600&nbsp;&nbsp;<img src="http://www.mycashfinance.com.au/email/Box.png"></p></td>
  </tr>
</tbody></table>
<br><br>












</div><!-- end .container -->




</body>
</html>